<?php

/*

  Action	$4

  +2 Actions
  Reveal cards from the top of your deck until you reveal an Action or Treasure card. Put that card into your hand and discard the other cards.

 */

class FarmingVillage extends Card implements iAction, iKingdom, iCornucopia {

    public function __construct() {
        parent::__construct("Farming Village", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+2 Actions",
            "Reveal cards from the top of your deck until you reveal an Action or Treasure card. Put that card into your hand and discard the other cards.");
    }
    
    public function play(Game $game, $isRealCard) {

        $game->addActions(2);
         ScreenDisplay::addScreenMessage($game, true, "get +2 actions", "gets +2 actions");

        //only looking on the top card
        $card = $game->peekCardFromDrawDeck();
        $discardCards = array();
        $good_card = null;
        while ($card != null) {
            if ($card instanceof iAction || $card instanceof iTreasure) {
                $good_card = $game->drawCards(1);
                break;
            } else {
               $card = $game->removeCardFromDrawDeck();
               $discardCards[] = $card;
            }             
             $card = $game->peekCardFromDrawDeck();
        }
        $game->discardTempDiscardCards($discardCards);
         ScreenDisplay::addScreenMessage($game, true, "discard ".  nicePrint($discardCards). " and put ".  nicePrint($good_card). " in your hand", 
                "discards ".  nicePrint($discardCards). " and puts ".  nicePrint($good_card). " in his hand");
        $game->cardActionFinished();
        return true;
    }

}

?>